<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cb extends CI_Controller {

    function __construct() 
	{
        parent::__construct();
        $this->load->library('flexigrid');
        $this->load->library('form_validation');
		$this->load->library('session');
        $this->load->helper('flexigrid');
        $this->load->helper(array('form', 'url'));
		$this->load->model('aktifitas_model');
		$this->load->model('proses_aktifitas_model');
        $this->load->model('bagian_jenis_aktifitas_model');
		$this->load->model('user_model');
		// $this->cek_session();
    }
    
	public function index($id_bagian_jenis_aktifitas)
	{
		if ($this->session->userdata('username') == NULL) 
		{
            redirect('login');
        } else {
						
		$hasil = $this->bagian_jenis_aktifitas_model->selectone($id_bagian_jenis_aktifitas);
		foreach ($hasil->result() as $row) 
		{
            $nama_bagian_jenis_aktifitas = $row->nama_bagian_jenis_aktifitas;
        }
		
		$this->session->set_userdata('id_bagian_jenis_aktifitas', $id_bagian_jenis_aktifitas);
		$this->session->set_userdata('nama_bagian_jenis_aktifitas', $nama_bagian_jenis_aktifitas);		  


		$colModel['no'] = array('No', 30, TRUE, 'center', 0);
		$colModel['nama_satuan_jenis_aktifitas'] = array('Satuan Aktifitas', 250, TRUE, 'center', 1);           
		$colModel['Lihat_Detail_Aktifitas'] = array('Lihat Detail Aktifitas', 100, TRUE, 'center', 0);

		//setting konfigurasi pada bottom tool bar flexigrid
        $gridParams = array(
                'width' => 'auto',
                'height' => 300,
                'rp' => 10,
                'rpOptions' => '[5,10,15,20,25,40]',
                'pagestat' => 'Menampilkan: {from} hingga {to} dari {total} data.',
                'blockOpacity' => 0.5,
                'title' => 'Daftar Aktifitas</br>Evaluasi : '.$this->session->userdata('NAMA_EVALUASI').'</br>Bagian Jenis Aktifitas : '.$nama_bagian_jenis_aktifitas.'',
                'showTableToggleBtn' => true
        );
            									
		//menambah tombol pada flexigrid top toolbar
	
			$buttons[] = array('Kembali ke Daftar Jenis Aktifitas', 'back', 'spt_js');	
			$buttons[] = array('separator');
		
				            		
		// mengambil data dari file controler ajax pada method grid_user				
		$grid_js = build_grid_js('flex1', site_url("cb/grid_foto/".$id_bagian_jenis_aktifitas.""), $colModel, 'nama_satuan_jenis_aktifitas', 'asc', $gridParams, $buttons);

        $data['added_js'] =
                    "<script type='text/javascript'>
        function spt_js(com,grid)
        {
                
				
				if (com=='Kembali ke Daftar Jenis Aktifitas')
                {
                        location.href='" . base_url() . "index.php/detail_aktifitas/index/".$this->session->userdata('ID_EVALUASI')."';
                }

                
        }
        </script>
        ";

            $data['js_grid'] = $grid_js;
            $data['content'] = $this->load->view('grid', $data, true);
            $this->load->view('main', $data);	
			}
	}
	
    function grid_foto($id_bagian_jenis_aktifitas) 
	{
        $valid_fields = array('nama_satuan_jenis_aktifitas');
        $this->flexigrid->validate_post('nama_satuan_jenis_aktifitas', 'asc', $valid_fields);
		// $records = $this->db->query("SELECT nama_satuan_jenis_aktifitas FROM satuan_jenis_aktifitas WHERE id_bagian_jenis_aktifitas = ".$id_bagian_jenis_aktifitas.";");		
		$records = $this->bagian_jenis_aktifitas_model->get_nama_satuan_aktifitas($id_bagian_jenis_aktifitas);
        $this->output->set_header($this->config->item('json_header'));
        $no = 0;

        foreach ($records['records']->result() as $row) {
            $record_items[] = array(
                $row->id_satuan_jenis_aktifitas,
                $no = $no + 1,
				$row->nama_satuan_jenis_aktifitas,
				'<a href=\'' . base_url() . 'index.php/aktifitas/index/' . $row->id_bagian_jenis_aktifitas . '\'><img border=\'0\' src=\'' . base_url() . 'images/grid/folder.png\'></a> '
            );
        }

        if (isset($record_items))
            $this->output->set_output($this->flexigrid->json_build($records['record_count'], $record_items));
        else
            $this->output->set_output('{"page":"1","total":"0","rows":[]}');
    }
	


	

}
